package com.design.classroommanagement

import android.os.Bundle
import android.view.View
import com.cf.holder.list.ListConfig
import com.cf.holder.list.ListManager
import com.design.classroommanagement.databinding.ListPageBinding
import com.laughing.lib.base.*
import com.laughing.lib.base.BaseListFragment
import com.laughing.lib.base.setTitle
import com.laughing.lib.utils.clickWithTrigger

abstract class BaseListFragment<DL : HBaseListViewModel> :
    BaseListFragment<DL, ListPageBinding>(),
    ListConfig<DL> {

    override fun initRefreshLayout(listManager: ListManager) {
        val refreshLayout = binding.refreshLayout
        listManager.setRefreshListener(refreshLayout.toListener())
        refreshLayout.setOnLoadMoreListener {
            listManager.loadMore()
        }
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.nav.backIv.clickWithTrigger {
            finish()
        }
        setTitle("xxxx")
        setOnTitleBarListener {
            leftClick = { _ ->
                finish()
            }
        }
    }

    override fun setLoadMoreEnable(enable: Boolean) {
        super.setLoadMoreEnable(enable)
        binding.refreshLayout.setEnableLoadMore(enable)
    }

    override fun setRefreshEnable(enable: Boolean) {
        super.setRefreshEnable(enable)
        binding.refreshLayout.setEnableRefresh(enable)
    }
}
